package NewCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wangchenghao
 * @date 2021/7/16
 **/
public class NC45 {
    public class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;
    }

    /**
     *
     * @param root TreeNode类 the root of binary tree
     * @return int整型二维数组
     */
    public int[][] threeOrders(TreeNode root) {
        // write code here

        List<Integer> preList = new ArrayList<>();
        List<Integer> inList = new ArrayList<>();
        List<Integer> postList = new ArrayList<>();
        preOrder(root, preList);
        inOrder(root, inList);
        postOrder(root, postList);
        int length=preList.size();
        int[][] result = new int[3][length];
        for (int i = 0; i <preList.size() ; i++) {
            result[0][i]=preList.get(i);
            result[1][i]=inList.get(i);
            result[2][i]=postList.get(i);
        }
        return result;
    }

    public void preOrder(TreeNode root, List<Integer> res) {
        if (root == null) {
            return;
        }
        res.add(root.val);
        preOrder(root.left, res);
        preOrder(root.right, res);
    }

    public void inOrder(TreeNode root, List<Integer> res) {
        if (root == null) {
            return;
        }
        inOrder(root.left, res);
        res.add(root.val);
        inOrder(root.right, res);
    }

    public void postOrder(TreeNode root, List<Integer> res) {
        if (root == null) {
            return;
        }
        postOrder(root.left, res);
        postOrder(root.right, res);
        res.add(root.val);
    }

    public void test(){
        List<Integer> res = new ArrayList<>();
        res.stream().mapToInt(Integer::valueOf).toArray();
    }
}
